// token判断
if (!sessionStorage.getItem('bigEventToken')) {
  location.href = '/login.html'
}

// 渲染个人信息：用户名+头像
async function getUserInfo() {
  const res = await reqUserInfoGet()
  console.log(res)
  // 身份信息不对时跳转登录页
  if (res.status !== 0) {
    location.href = '/login.html'
  }
  let { nickname, user_pic, username } = res.data
  // 用户名
  if (nickname) {
    username = nickname
  }
  $('.userinfo .username').text(username)
  // 头像
  if (!user_pic) {
    $('.avatar').css('display', 'inline-block').text(username[0].toUpperCase())
  } else {
    $('.userinfo img').css('display', 'inline-block').prop('src', user_pic)
    $('.avatar').css('display', 'none')
  }
}
getUserInfo()

// 退出
$('#logout').on('click', () => {
  layer.confirm('是否确认退出?', { icon: 3, title: '提示' }, () => {
    sessionStorage.removeItem('bigEventToken')
    location.href = '/login.html'
  })
})
